package com.suitsoft.bdms.web.imp;

import java.io.IOException;
import java.io.PrintWriter;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.opensymphony.xwork2.ActionSupport;
import com.suitsoft.bdms.commos.LogAnnotation;
import com.suitsoft.bdms.service.imp.ImpManager;

/**
 * 基础数据导入
 *@author Suine
 */
@SuppressWarnings("serial")
@Results(@Result(location="imp.action",name="reload",type="redirect"))
public class ImpAction extends ActionSupport{
	/** 日志输出对象 */
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	private ImpManager impManager;
	
	private PrintWriter out = null;
	private String msg = "";
	
	private String fistYear;
	private String endYear;
	private String xq;

	@LogAnnotation(log = "基础数据导入 - 学生")
	public String student(){
		try {
			out = Struts2Utils.getResponse().getWriter();
			try {
				impManager.student();
				msg = "操作成功";
			} catch (Exception e) {
				e.printStackTrace();
				msg = "操作失败";
			}
			out.print(msg);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	@LogAnnotation(log = "基础数据导入 - 教师")
	public String teacher(){
		try {
			out = Struts2Utils.getResponse().getWriter();
			try {
				impManager.teacher();
				msg = "操作成功";
			} catch (Exception e) {
				e.printStackTrace();
				msg = "操作失败";
			}
			out.print(msg);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	@LogAnnotation(log = "基础数据导入 - 学院")
	public String department(){
		try {
			out = Struts2Utils.getResponse().getWriter();
			try {

				impManager.department();
				msg = "操作成功";
			} catch (Exception e) {
				e.printStackTrace();
				msg = "操作失败";
			}
			out.print(msg);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	@LogAnnotation(log = "基础数据导入 - 考研室")
	public String staffroom(){
		try {
			out = Struts2Utils.getResponse().getWriter();
			try {
				impManager.staffroom();
				msg = "操作成功";
			} catch (Exception e) {
				e.printStackTrace();
				msg = "操作失败";
			}
			out.print(msg);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	@LogAnnotation(log = "基础数据导入 - 班级")
	public String baseClass(){
		try {
			out = Struts2Utils.getResponse().getWriter();
			try {
				impManager.baseClass();
				msg = "操作成功";
			} catch (Exception e) {
				e.printStackTrace();
				msg = "操作失败";
			}
			out.print(msg);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	@LogAnnotation(log = "基础数据导入 - 专业")
	public String major(){
		try {
			out = Struts2Utils.getResponse().getWriter();
			try {
				impManager.major();
				// 专业导入之后。同时把关系连上
				impManager.departmentMajor();
				msg = "操作成功";
			} catch (Exception e) {
				e.printStackTrace();
				msg = "操作失败";
			}
			out.print(msg);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	@LogAnnotation(log = "基础数据导入 - 学生选课")
	public String studentTask(){
		try {
			out = Struts2Utils.getResponse().getWriter();
			try {
				String xn = fistYear + "-" + endYear;
				impManager.studentTask(xn,xq);
				msg = "操作成功";
			} catch (Exception e) {
				e.printStackTrace();
				msg = "操作失败";
			}
			out.print(msg);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	@LogAnnotation(log = "基础数据导入 - 教师选课")
	public String teacherTask(){
		try {
			out = Struts2Utils.getResponse().getWriter();
			try {
				impManager.teacherTask();
				msg = "操作成功";
			} catch (Exception e) {
				e.printStackTrace();
				msg = "操作失败";
			}
			out.print(msg);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	@LogAnnotation(log = "基础数据导入 - 职称")
	public String post(){
		try {
			out = Struts2Utils.getResponse().getWriter();
			try {
				impManager.post();
				msg = "操作成功";
			} catch (Exception e) {
				e.printStackTrace();
				msg = "操作失败";
			}
			out.print(msg);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	@LogAnnotation(log = "基础数据导入 - 学院与专业关联")
	public String departmentMajor(){
		try {
			out = Struts2Utils.getResponse().getWriter();
			try {
				impManager.departmentMajor();
				msg = "操作成功";
			} catch (Exception e) {
				e.printStackTrace();
				msg = "操作失败";
			}
			out.print(msg);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	@Autowired
	public void setImpManager(ImpManager impManager) {
		this.impManager = impManager;
	}

	public String getFistYear() {
		return fistYear;
	}

	public void setFistYear(String fistYear) {
		this.fistYear = fistYear;
	}

	public String getEndYear() {
		return endYear;
	}

	public void setEndYear(String endYear) {
		this.endYear = endYear;
	}

	public String getXq() {
		return xq;
	}

	public void setXq(String xq) {
		this.xq = xq;
	}
}

